package app.ple.pi.Adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import app.ple.pi.powerdinner.R;
import app.ple.pi.powerdinner.Board.BoardDTO;

public class ListAdapter extends ArrayAdapter<BoardDTO> {
	private ArrayList<BoardDTO> list;
	private Context context;
	public ListAdapter(Context context,int textViewResourceId, ArrayList<BoardDTO> list){
		super(context,textViewResourceId);
		this.list=list;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if(v==null){
			LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.list_cell, null);
		}
		BoardDTO dto = list.get(position);
		if(dto==null){
			TextView title = (TextView)v.findViewById(R.id.title);
			TextView phoneNum = (TextView)v.findViewById(R.id.phone);
			TextView name = (TextView)v.findViewById(R.id.name);
			TextView location = (TextView)v.findViewById(R.id.location);
			if(title!=null){
				title.setText(dto.getTitle());
			}else if(phoneNum!=null){
				phoneNum.setText(dto.getPhoneNum());
			}else if(name!=null){
				name.setText(dto.getUserName());
			}else if(location!=null){
				location.setText(dto.getLocation());
			}
			
		}
		return v;
	}
	

	
}
